package com.tool.btn;

import com.tool.role.RoleData;
import com.tool.tcpimg.UIUtils;
import org.come.Jpanel.TestPetJpanel;
import org.come.action.petpaixu.PetpxJpanel;

import javax.swing.*;
import java.awt.event.MouseEvent;
import java.util.List;

public class PetOrderBtn extends MoBanBtn{

    //0上 1下 2顶 3底
    private PetpxJpanel jpanel;
    private int p;
    public PetOrderBtn(String iconpath,int type,int p,PetpxJpanel jpanel) {
        super(iconpath, type);
        // TODO Auto-generated constructor stub
        this.p=p;
        this.jpanel=jpanel;


    }

    public PetOrderBtn(String iconpath, int type,int p,String text,PetpxJpanel jpanel) {
        // TODO Auto-generated constructor stub
        super(iconpath, type, UIUtils.COLOR_BTNTEXT);
        this.setText(text);
        this.setFont(UIUtils.TEXT_FONT);
        setVerticalTextPosition(SwingConstants.CENTER);
        setHorizontalTextPosition(SwingConstants.CENTER);
        this.p=p;
        this.jpanel = jpanel;
    }
    @Override
    public void chooseyes() {
        // TODO Auto-generated method stub

    }

    @Override
    public void chooseno() {
        // TODO Auto-generated method stub

    }

    @Override
    public void nochoose(MouseEvent e) {
        // TODO Auto-generated method stub
        //获取当前选中的位置
        int currentIndex = jpanel.getListpet().getSelectedIndex();
        if (currentIndex == -1) {
            return;
        }
        RoleData data = RoleData.getRoleData();

        //0上 1下 2顶 3底
        int index = -1;
        if (p == 0) {
            index = currentIndex - 1;
        } else if (p == 1) {
            index = currentIndex + 1;
        } else if (p == 2) {
            index = 0;
        } else {
            index = data.getPetOrder().size() - 1;
        }
        List<String> list = data.updateOrderPet(currentIndex, index);
        if (list != null) {
            jpanel.init(list,index);
        }
        TestPetJpanel.showStar();
    }
}
